<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"></script>
</head>
<body>
  <div id="root">
    <!-- 插值表达式 -->
    {{title}}
    <!-- <input 
      type="text" 
      v-bind:value="textValue"
      v-on:input="handleInput"
    > -->
    <input type="text" v-model="textValue" v-on:keyup.enter="handleKeyUp">
    <ul>
      <li v-for="(fruit, index) in fruits">
        {{fruit}} <button v-on:click="handleClick(index)">X</button>
      </li>
    </ul>
  </div>
  <script>
    new Vue({
      data: {
        title: '请输入：',
        textValue: '',
        fruits: [
          '🍇',
          '🍌',
          '🍉'
        ]
      },

      methods: {
        // handleInput(e) {
        //   this.fruits.push(e.target.value)
        // }
        handleKeyUp() {
          this.fruits.push(this.textValue)
          this.textValue = ''
        },

        handleClick(index) {
          this.fruits.splice(index, 1)
        }
      },

      el: '#root'
    })
  </script>
</body>
</html>